import tkinter as tk
import sys
from PIL import ImageTk, Image
from shengcun import shengcun
from wujin import wujin
import paihangbang

def zhuyemian():
    root = tk.Tk()

    #背景

    def jinru():
        
        root.destroy()
        global root1
        root1=tk.Tk()
        shengcun()
        root1.mainloop()
    def jinru1():
        
        root.destroy()
        global root2
        root2=tk.Tk()
        wujin()
        root1.mainloop()
    def jinru2():
        root.destroy()#将当前的Tk()对象销毁 一个程序只允许有一个Tk()
      
        paihangbang.paihangbang()
        global root3
        root3 =tk.Tk()
        paihangbang.paihangbang()
        root3.mainloop()
    def tuichu():
        root.destroy()
        sys.exit()
    canvas = tk.Canvas(root, width=640,height=480,bd=0, highlightthickness=0)#设置窗口宽高
    imgpath = 'bg.gif'
    img = Image.open(imgpath)
    photo = ImageTk.PhotoImage(img)#背景
    root.title('主页面')#标题
    canvas.create_image(320, 240, image=photo)#图片位置
    canvas.pack()#加载到窗体

    #root.geometry("640x480+320+120")
    #无尽模式按钮
    temping = tk.PhotoImage(file="1.png")#以变量方式加载图片磁盘位置
    button_wujin=tk.Button(image = temping,bd=-1,command=jinru1 )
     #收到消息执行函数 button_wujin=tk.Button(image = temping , command=wujin)
    button_wujin.pack()#加载到窗体
    button_wujin.place(x=260, y=170)#设置按钮位置

    #生存模式按钮
    temping1 = tk.PhotoImage(file="2.png")
    #button_shengcun=tk.Button(image = temping1,bd=-1  )
     #收到消息执行函数
    button_shengcun=tk.Button(image = temping1,bd=-1, command=jinru)

    button_shengcun.pack()#加载到窗体
    button_shengcun.place(x=260, y=240)

    #排行榜按钮
    temping2 = tk.PhotoImage(file="3.png")
    button_paihangbang=tk.Button(image = temping2 ,bd=-1,command=jinru2)
     #收到消息执行函数 button_paihangbang=tk.Button(image = temping2, command= paihang)
    button_paihangbang.pack()#加载到窗体
    button_paihangbang.place(x=260, y=310)
    #退出按钮
    temping3 = tk.PhotoImage(file="6.png")
    button_tuichu=tk.Button(image = temping3 ,bd=-1,command=tuichu)
     #收到消息执行函数 button_paihangbang=tk.Button(image = temping2, command= paihang)
    button_tuichu.pack()#加载到窗体
    button_tuichu.place(x=260, y=380)

    
    root.mainloop()#进入消息循环机制

    


if __name__ == '__main__':
    zhuyemian()

